package com.ldl.framework.mvc.controller;

import com.ldl.framework.mvc.annotation.LdlAutowired;
import com.ldl.framework.mvc.annotation.LdlController;
import com.ldl.framework.mvc.annotation.LdlRequestMapping;
import com.ldl.framework.mvc.annotation.LdlRequestParam;
import com.ldl.framework.mvc.controller.service.DemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ldl  想过夏天的雪人
 * @Date 2022-10-12 11:38
 */
@LdlController
@LdlRequestMapping("/demo")
public class DemoController {
    @LdlAutowired
    private DemoService demoService;

    @LdlRequestMapping("/hello")
    public void hello(HttpServletRequest req, HttpServletResponse resp,
                      @LdlRequestParam("name") String name) {
        String result = "My name is " + name;
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @LdlRequestMapping("/add")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @LdlRequestParam("name") String name, @LdlRequestParam("sex") String sex,
                    @LdlRequestParam("id") String id) {
        try {
            resp.getWriter().write(demoService.add(name, sex, id));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
